
<%@ page import="com.webboard.Post"
import="com.webboard.Reply"
%>

<%def ipAddressUrl = grailsApplication.config.ipAddressUrl%>

<html>
  <head>
  <resource:richTextEditor type="full" />
  <resource:tabView />
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <meta name="layout" content="main" />
  <g:set var="entityName" value="${message(code: 'post.label', default: 'Post')}" />
  <title>${postInstance?.title}</title>
</head>
<body>
  <div class="nav">
    <span class="menuButton"><g:link class="list" action="list"><g:message code="default.list.label" args="[entityName]" /></g:link></span>
    <span class="menuButton"><g:link class="create" action="create"><g:message code="default.new.label" args="[entityName]" /></g:link></span>
  </div>
  <div class="body">
    <h1>${postInstance?.title}</h1> <!--Header of Body page-->
    <g:if test="${flash.message}">
      <div class="message">${flash.message}</div>
    </g:if>

    <g:hasErrors bean="${replyInstance}">
      <div class="errors">
        <g:renderErrors bean="${replyInstance}" as="list" />
      </div>
    </g:hasErrors>

    <!--Show post-->
    <div class="dialog">
      <table border="1">
        <tbody>

          <tr class="prop">
            <td valign="top" class="name"><g:message code="post.title.label" default="Title" /></td>
        <td valign="top" class="value">${fieldValue(bean: postInstance, field: "title")}</td>
        </tr>

        <tr class="prop">
          <td valign="top" class="name"><g:message code="post.username.label" default="Username" /></td>
        <g:if test="${postInstance.user != null}">
          <td width="60%">โดย : <g:link controller="user" action="showToUser" id="${postInstance.user?.id}">${postInstance?.username}</g:link></td>
        </g:if>
        <g:else>
          <td width="60%">โดย : ${postInstance?.username}</td>
        </g:else>
        </tr>

        <tr class="prop" style="height: 100px">
          <td valign="top" class="value" colspan="2" >${myformatToHtmlService.toHtmlTagWebboard(postInstance?.text)}</td>
        </tr>



        <tr class="prop">
          <td valign="top" class="value"><g:formatDate date="${postInstance?.postDate}" /></td>
        <td>ipAddress : <g:link url="http://whatismyipaddress.com/ip/${postInstance?.ipAddress_client}">${postInstance?.ipAddress_client}</g:link></td>
        </tr>
        <tr class="prop">
          <td colspan="2"><b:bookmark title="${postInstance?.title}" permalink="${ipAddressUrl}/telemedicine/post/show/${postInstance?.id}" type="addtoany"/></td>
        </tr>
        </tbody>
      </table>
    </div>
    <!--End Show post-->

    <div class="buttons">
      <!--Show List of Reply-->
      <g:each in="${replyList}" var="r">
        <table border="1">
          <tr style="height: 100px">
            <td colspan="2" >${myformatToHtmlService.toHtmlTagWebboard(r?.text)}</td>
          </tr>
          <tr>
            <td>ipAddress : <g:link url="http://whatismyipaddress.com/ip/${r?.ipAddress_client}">${r?.ipAddress_client}</g:link></td>
          <td>[ ${r?.replyDate} ]</td>
          <tr>
          <tr>
          <g:if test="${r.user != null}">
            <td>โดย : <g:link controller="user" action="showToUser" id="${r.user?.id}">${r?.username}</g:link></td>
          </g:if>
          <g:else>
            <td>โดย noLogin: ${r?.username}</td>
          </g:else>
          <td>#ความคิดเห็นที่ ${r?.id_replyOfPost}</td>
          </tr>
        </table>
        <br/>
        <br/>
      </g:each>
      <!--End Show List of Reply-->

      <!--Reply Create Code-->
      <g:form controller="reply" action="save">
          <g:hiddenField name="postId" value="${postInstance.id}"/>
          <richui:richTextEditor name="text" value="${replyInstance?.text}" height="500"/>
          <table border="0">
            <tbody>

            <tr class="prop">
              <td valign="top" class="name">
                <label for="username"><g:message code="reply.username.label" default="Username" /></label>
              </td>

              <td valign="top" class="value ${hasErrors(bean: replyInstance, field: 'username', 'errors')}">
            <g:isLoggedIn>
              <g:hiddenField name="username" value="${loggedInUserInfo(field:'username')}"/>
              <g:loggedInUserInfo field="username"/>
            </g:isLoggedIn>
            <g:isNotLoggedIn>
              <g:textField style="width: 90%;color: fuchsia; background-color:Black;border: solid red" name="username" value="${replyInstance?.username}" />
            </g:isNotLoggedIn>
            </td>
            </tr>

            </tbody>
          </table>
        <div class="buttons">
          <span class="button"><g:submitButton name="create" class="save" value="${message(code: 'default.button.create.label', default: 'Create')}" /></span>
        </div>
      </g:form>
      <!-- End of Reply Create Code -->
      <g:form>
        <g:hiddenField name="id" value="${postInstance?.id}" />
        <span class="button"><g:actionSubmit class="edit" action="edit" value="${message(code: 'default.button.edit.label', default: 'Edit')}" /></span>
        <span class="button"><g:actionSubmit class="delete" action="delete" value="${message(code: 'default.button.delete.label', default: 'Delete')}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');" /></span>
      </g:form>
    </div>
  </div>
</body>
</html>
